﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WenSkin.Controls;

namespace WenSkinTest.UserControlAll
{
    public partial class TreeViewControl : WenSkin.Controls.WenUserControl
    {
        public TreeViewControl()
        {
            InitializeComponent();
        }

        private void wenLineTextBox1_ButtonClick(object sender, EventArgs e)
        {
            this.MsgBoxAsterisk("鼠标点击");
        }

        private void wenTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void wenLineTextBox1_Click(object sender, EventArgs e)
        {

        }

        private void wenLineTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void wenButton1_Click(object sender, EventArgs e)
        {
            wenLable1.Size = new Size(500, 500);
        }

        protected override void CreateHandle()
        {
            base.CreateHandle();
            if (headerNativeWindow == null)
            {
                headerNativeWindow = new HeaderNativeWindow(this);
            }
        }


        #region 创建消息 TextBox 消息拦截重绘
        private HeaderNativeWindow headerNativeWindow;
        private void TextBox_HandleDestroyed(object sender, EventArgs e)
        {
            if (headerNativeWindow != null)
            {
                headerNativeWindow = null;
            }
        }

        private void TextBox_HandleCreated(object sender, EventArgs e)
        {
            if (headerNativeWindow == null)
            {
                headerNativeWindow = new HeaderNativeWindow(this);
            }
        }

        private class HeaderNativeWindow : NativeWindow
        {
            private readonly TreeViewControl owner;
            readonly IntPtr header;
            public HeaderNativeWindow(TreeViewControl owner)
            {
                this.owner = owner;
                header = owner.panel1.Handle;
                base.AssignHandle(header);
            }
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                if (m.Msg == 0xf || m.Msg == 0x133)
                {
                    using Graphics g = Graphics.FromHwnd(m.HWnd).SetGDIHigh();
                    //当文本为空，提示文本不为空，水印TextBox
                    //g.FillRectangle(Brushes.Red, new RectangleF(0, 0, 500, 500));
                }
                else if (m.Msg == 0x0137 || m.Msg == 0x0138)
                {
                    Console.WriteLine(m.Msg);
                }
            }
        }

        #endregion
    }
}
